package com.informationsystem.model;

import static javax.persistence.GenerationType.IDENTITY;

import com.informationsystem.model.BaseObject;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="picture_news")
@Indexed
@XmlRootElement
public class PictureNews extends BaseObject implements Serializable {
    private String pictureName;
    private News news;
    public Long id;
    
    @Id  @GeneratedValue(strategy=IDENTITY) @DocumentId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PictureNews pojo = (PictureNews) o;

        if (pictureName != null ? !pictureName.equals(pojo.pictureName) : pojo.pictureName != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = 31 * result + (pictureName != null ? pictureName.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("content").append("='").append(getPictureName()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }
    
    @Column(name="pictureName", nullable=false, length=10000)
    @Field
	public String getPictureName() {
		return pictureName;
	}

	public void setPictureName(String pictureName) {
		this.pictureName = pictureName;
	}

	@OneToOne(fetch=FetchType.EAGER, cascade = {CascadeType.REFRESH},optional = false)
	public News getNews() {
		return news;
	}

	public void setNews(News news) {
		this.news = news;
	}

}
